home *** CD-ROM | disk | FTP | other *** search
- ;void print_char(ch,number);
- ; char ch;
- ; unsigned short number;
-
- EXTRN _memory_model:byte
- EXTRN _error_code:byte
- EXTRN _time_out:byte
-
- _TEXT SEGMENT BYTE PUBLIC 'CODE'
- ASSUME CS:_TEXT
- PUBLIC _print_char
- _print_char proc near
- push bp ;
- mov bp,sp ;
- push si ;
- cmp _memory_model,0 ;near or far?
- jle begin ;jump if near
- inc bp ;else add 2 to BP
- inc bp ;
- begin: mov _error_code,1 ;1 = printer error
- mov ah,1 ;BIOS func to init prtr
- mov dx,0 ;choose LPT1
- int 17h ;initialize the prtr port
- sub ax,ax ;clear AX
- mov es,ax ;pt ES to 0000:0000
- mov dx,es:[408H] ;get LPT1 base address
- sub cx,cx ;clear CX
- mov cl,[bp+6] ;number chars (255 limit)
- jcxz L3 ;quit if 0
- mov al,_time_out ;get _time_out seconds
- or al,al ;don't allow zero
- jnz L1 ;
- mov al,3 ;default to 3 seconds
- L1: mov bl,18 ;18 ticks per second
- mul bl ;
- mov [bp+6],ax ;save count
- mov bl,[bp+4] ;keep char in bl
- L2: mov al,bl ;character to AL
- call Writeit ;
- or ah,ah ;test for error
- jz L3 ;quit if error
- loop L2 ;go write next char
- mov _error_code,0 ;0 = no error
- L3: pop si ;
- pop bp ;
- cmp _memory_model,0 ;quit
- jle quit ;
- db 0CBh ;RET far
- quit: ret ;RET near
- Writeit PROC
- out dx,al ;send to output data register
- inc dx ;forward to status register
- push cx ;save string counter
- call GetBiosCount ;get timer reading
- mov si,cx ;make copy
- add cx,[bp+6] ;add delay count
- cmp si,cx ;if timer doesn't turn over...
- jb L4 ;go ahead
- mov cx,[bp+6] ;otherwise, extend delay
- L4: mov [bp+4],cx ;save target count on stack
- Wait: in al,dx ;get status value
- test al,8 ;test for printer error
- jz Error ;
- test al,80h ;test for Printer Ready
- jnz Ready ;jump if ready
- Error: call GetBiosCount ;
- cmp cx,[bp+4] ;compare to target
- jb Wait ;
- pop cx ;restore string counter
- mov ah,0 ;return code for failure
- jmp short L5 ;return
- Ready: pop cx ;restore string counter
- inc dx ; output control register
- mov al,13 ;bits for strobe signal
- out dx,al ;send the signal
- dec al ;change to strobe OFF
- out dx,al ;send the signal
- dec dx ;point back to
- dec dx ; base address
- mov ah,1 ;return code for success
- L5: ret ;
- Writeit endp
- GetBIOSCount PROC
- push dx ;return value in CX:DX
- push ax ;
- sub ah,ah ;function number
- int 1ah ;get timer count
- mov cx,dx ;low word in CX
- pop ax ;
- pop dx
- ret
- GetBIOSCount endp
- _print_char endp
- _TEXT ENDS
- END